import 'package:myturngame/bean/game_map.dart';
import 'package:myturngame/bean/role_in_combat.dart';
import 'package:myturngame/common/game_global.dart';

import '../bean/role.dart';
import '../bean/role_in_map.dart';

class EnemyFactory {}

///生成地图中的敌人
// List<RoleInMap> createMapEnemy(String map) {
//   if (map == GameMap.map001) {
//     return List.empty();
//   } else if (map == GameMap.map002) {
//     return [RoleInMap("大海龟", 1), RoleInMap("海毛虫", 2)];
//   } else if (map == GameMap.map003) {
//     return [RoleInMap("青蛙", 3), RoleInMap("海毛虫", 2)];
//   } else {
//     return List.empty();
//   }
// }

RoleInMap? createMapEnemy(String map){
  if (map == GameMap.map002) {
    return RoleInMap('enemy001'.enemyName());
  } else if (map == GameMap.map003) {
    return RoleInMap('enemy002'.enemyName());
  } else {
    return null;
  }
}

///生成战斗敌人
void createCombatEnemy(RoleInMap roleInMap, List<RoleInCombat?> enemyList) {
  _enemyEnterTeam([createMonster(roleInMap.name), createMonster(roleInMap.name)], enemyList);
}

Role createMonster(String name){
  if(name == 'enemy001'.enemyName()){
    return Role(name)
      ..hp = 30
      ..baseAttrList[AttributeSet.startMaxHp] = 30
      ..baseAttrList[AttributeSet.startAttack] = 5
      ..attributeSettlement();
  }else if(name == 'enemy002'.enemyName()){
    return Role(name)
      ..hp = 100
      ..baseAttrList[AttributeSet.startMaxHp] = 100
      ..baseAttrList[AttributeSet.startAttack] = 20
      ..attributeSettlement();
  }else{
    return Role(name);
  }
}

void _enemyEnterTeam(List<Role> enemyList, List<RoleInCombat?> team) {
  var enterIndexOrder = [2, 3, 4, 1, 5, 7, 8, 9, 6, 10];
  for (int i = 0; i < enemyList.length; i++) {
    var enterIndex = enterIndexOrder[i]-1;
    team[enterIndex] = RoleInCombat(enemyList[i], enterIndex,RoleInCombat.teamEnemy);
  }
}
